<?php if(!defined('SABLOG_ROOT')) exit('Access Denied');?>
<div id="submenu">
	<ul>
		<li><a href="cp.php?job=attachment&action=list" <!--{if $action == 'list' && !$view}-->class="focus"<!--{/if}-->><span>附件管理</span></a></li>
		<li><a href="cp.php?job=attachment&action=repair" <!--{if $action == 'repair'}-->class="focus"<!--{/if}-->><span>附件修复</span></a></li>
		<li><a href="cp.php?job=attachment&action=clear" <!--{if $action == 'clear'}-->class="focus"<!--{/if}-->><span>附件清理</span></a></li>
		<li><a href="cp.php?job=attachment&action=stats" <!--{if $action == 'stats'}-->class="focus"<!--{/if}-->><span>附件统计</span></a></li>
		<li></li>
	</ul>
</div>

<div id="wrap">
<p class="p_nav"><a href="cp.php?job=attachment&action=list&view=image&articleid=$articleid">查看图片附件</a> | <a href="cp.php?job=attachment&action=list&view=file&articleid=$articleid">查看非图片附件</a></p>
<!--{if $action == 'list'}-->
	<!--{if $articleid}-->
	<h2>上传新附件到该文章&raquo;</h2>
	<form action="cp.php?job=attachment" method="post" enctype="multipart/form-data">
	<div class="input">
		<h2>选择文件 <a href="###" onclick="addattachfrom();">[+]</a>&nbsp;<a href="###" onclick="removeattachfrom();">[-]</a></h2>
		<p>
			<table align="center" border="0" cellspacing="0" cellpadding="0">
				<tbody id="attachbodyhidden" style="display:none"><tr><td>附件: <input class="formfield" type="file" name="attach[]" /></td></tr></tbody>
				<tbody id="attachbody"><tr><td>附件: <input class="formfield" type="file" name="attach[]" /></td></tr></tbody>
			</table>
			<span class="describe">图片超过2M缩略图和水印均不生效.如果上传大于2M的图片请自行处理</span>
		</p>
	</div>
	<div class="submit">
		<input type="hidden" name="action" value="addattachtoarticle" />
		<input type="hidden" name="articleid" value="$articleid" />
		<button type="submit">确认</button>
	</div>
	</form>
	<div style="clear:both;"></div>
	<!--{/if}-->
	<h2>$article[title] 附件列表&raquo;</h2>
	<form action="cp.php?job=attachment"  method="post">
		<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
			<tr class="tdbheader">
				<td nowrap>附件名</td>
				<td nowrap>附件信息</td>
				<td nowrap>所在目录</td>
				<td nowrap>缩略图</td>
				<td nowrap>上传时间</td>
				<td nowrap>下载次数</td>
				<td nowrap>文章</td>
				<td width="5%" nowrap><input name="chkall" value="on" type="checkbox" onclick="checkall(this.form)" /></td>
			</tr>
			<!--{loop $attachdb $attach}-->
			<!--{eval $thisbg = isset($thisbg) && $thisbg == 'tablecell' ? 'tablecell2' : 'tablecell';}-->
			<tr class="$thisbg" onmouseover="this.className='cellfocus';" onmouseout="this.className='$thisbg';">
				<td><a href="attachment.php?id=$attach[attachmentid]" target="_blank" title="$attach[filepath]">$attach[filename]</a></td>
				<td>大小:$attach[filesize]<br />
				类型:$attach[filetype]</td>
				<td>$attach[subdir]</td>
				<td><!--{if $attach['thumb_filepath']}--><a href="{$options[attachments_dir]}{$attach[thumb_filepath]}" target="_blank"><font color="#FF0000">有</font></a><!--{else}-->无<!--{/if}--></td>
				<td nowrap>$attach[dateline]</td>
				<td>$attach[downloads]</td>
				<td nowrap><a title="$attach[article]" href="index.php?action=show&id=$attach[articleid]" target="_blank">查看</a></td>
				<td nowrap><input type="checkbox" name="attachment[]" value="$attach[attachmentid]" /></td>
			</tr>
			<!--{/loop}-->
			<tr class="tablecell">
				<td colspan="8" nowrap><div class="records">记录:$total</div>
				<div class="multipage">$multipage</div></td>
			</tr>
		</table>
		<div class="submit">
			<input type="hidden" name="action" value="delattachments" />
			<input type="hidden" name="articleid" value="$articleid" />
			<button type="submit">删除所选附件</button>
		</div>
	</form>
<!--{elseif $action == 'repair'}-->
		<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
        <form action="cp.php?job=attachment" method="post">
          <input type="hidden" name="action" value="dorepair" />
          <tr>
            <td class="alertbox">
			<p>本功能清除数据库那存在附件记录而没有附件文件的冗余数据，文章中的附件记录也将同时更新。</p>
            <p>如果附件较多，过程会比较久，请耐心等候。</p>
            <p>建议定期执行。</p>
            <p><button type="submit">确认</button></p>
			</td>
          </tr>
        </form>
		</table>
<!--{elseif $action == 'clear'}-->
		<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
        <form action="cp.php?job=attachment" method="post">
          <input type="hidden" name="action" value="doclear" />
          <tr>
            <td class="alertbox">
			<p>本功能删除数据库中没有记录而实际存在的附件，可有效清理冗余附件。</p>
            <p>循环处理数量: <input class="formfield" type="text" name="percount" value="500" size="5" /></p>
            <p><button type="submit">确认</button></p>
			</td>
          </tr>
        </form>
		</table>
<!--{elseif $action == 'stats'}-->
	<ul class="info">
		<li><u>附件数量:</u>$stats[count] 个</li>
		<li><u>记录附件大小:</u>$stats[sum]</li>
		<li><u>实际附件大小:</u>$realattachsize</li>
		<li><u>附件存放路径:</u>$a_dir <!--{if $warning}--><font color="#FF0000"><strong>(文件夹无效,请重新设定上传文件夹!)</strong></font><!--{/if}--></li>
		<li><u>附件子目录数:</u>$dircount 个</li>
	</ul>
<!--{/if}-->